#include "mainmodeencrypt.h"
#include <QTime>
#include <QDebug>
#include <QCoreApplication>
#include <QDir>
#include <QMessageBox>
MainModeEncrypt::MainModeEncrypt()
{
    modeName = "MathMain";
    fileName = "mathLicense.xml";

}
QString MainModeEncrypt::encodeRegisterNumber(QString strSerialNumber,QString strDate)
{
    ModeEncryptBase objModeEncrypt(ModeEncryptBase::E_ProgramModeType_MAIN);
    QString registerNumber = objModeEncrypt.encryptLicense(strSerialNumber,strDate);
    ManageFile objManageFile;
    QString mainModePath=objManageFile.GetCurrentApplicationPath();
    mainModePath += QString("/license/")+strSerialNumber;
    if(!objManageFile.isDirExist(mainModePath))
    {
        QMessageBox::about(NULL,QString::fromLocal8Bit("提示"),QString::fromLocal8Bit("模块文件夹创建失败！"));
    }

    mainModePath += QString("/")+fileName;
    //写入xml文件
    ReadWriteXml objReadWriteXml;
    ReadWriteXml::WriteInfo objWriteInfo;
    objWriteInfo.encryptType=QString::number(static_cast<int>(objModeEncrypt.emEncryptModeType));
    objWriteInfo.endDate=strDate;
    objWriteInfo.modeName=modeName;
    objWriteInfo.serialNumber=strSerialNumber;
    objWriteInfo.licenseCode=registerNumber;

    objWriteInfo.licenseCode.replace("-","");
    if(objReadWriteXml.WriteRegisterInfo(objWriteInfo,mainModePath)!= 1)
    {
        QMessageBox::about(NULL,QString::fromLocal8Bit("提示"),QString::fromLocal8Bit("license文件生成失败！"));
    }
    return registerNumber;
}

